<?php
require_once 'OAuthRequestVerifier.php';
require_once 'OAuthResponse.php';

/**
 * Class OAuthServerBase
 *
 * Description for class OAuthServerBase
 *
 * @author: Phong Linh <langxangvn@gmail.com>
*/
class OAuthServerBase extends OAuthRequestVerifier {	
	
	/**
	* OAuth parameter prefix
	*/
	public static $SESSION_NAMESPACE = "OAUTH-NS";
	
	/**
	 * This is method fault
	 *
	 * @param mixed $exception This is a description
	 * @param mixed $format This is a description	 
	 * @param mixed $httpCode This is a description
	 * @return mixed This is the return value description
	 *
	 */
	public function fault($exception = null, $format = 'json', $httpCode = null) {		
		$error = false;
		if ($exception instanceof OAuthException) {
			$error = array('code' => $exception->getCode(), 
				'msg' => $exception->getMessage());			
		} else if ($exception instanceof Exception) {
			$error = array('code' => $exception->getCode(), 
				'msg' => $exception->getMessage());
		} else {
			$error = $_ERRORS[self::$BAD_URL];
		}
		
		switch ($format) {
			case 'xml':
				$errorXml = OAuthResponse::error($error['code'], $error['msg']);
				return $errorXml;
			
			case 'plain-text':
				return OAuthResponse::plain($error);
			
			case 'json':
				$errorXml = OAuthResponse::error($error['code'], $error['msg'], false);
				return Zend_Json::fromXml($errorXml);
		}
	}
	
	/**
	 * This is method handle
	 *
	 * @return mixed This is the return value description
	 *
	 */
	public function handle($action) {			
		return $this->getVersion();	// dummy method
	}
	
	/**
	 * This is method getVersion
	 *
	 * @return mixed This is the return value description
	 *
	 */
	public function getVersion() {
		return array('version' => 1.0);
	}
}

?>